package inventory.utils;

import inventory.entity.InRepositoryRecord;
import inventory.entity.MaterialStuff;
import inventory.entity.bo.MaterialBo;

import java.util.Date;

public class MaterialInitUtil {

    /**
     * 初始化InRepositoryRecord
     * @param materialBo 初始化InRepositoryRecord时前端传过来的相应参数 ， 包含 材料类型id 、 操作者id 、 目标仓库id 、原始仓库
     * @return
     */
    public static InRepositoryRecord initInRepositoryRecord(MaterialBo materialBo) {
        InRepositoryRecord record = new InRepositoryRecord();
        if (materialBo.getCount()==null){
            record.setCount(Long.valueOf(0));
        }else {
            record.setCount(Long.valueOf(materialBo.getCount()));
        }
        record.setInRepositoryRecordId(UUIDUtils.getId());
        record.setInTime(new Date());
        record.setTypicalId(materialBo.getMaterialTypicalId());
        record.setOperator(materialBo.getOperator());

        if (materialBo.getSourceRepositoryId() != null && materialBo.getSourceRepositoryId().equals("")){
            record.setSource(null);
        }else {
            record.setSource(materialBo.getSourceRepositoryId());
        }

        if (materialBo.getTargetRepositoryId() != null && materialBo.getTargetRepositoryId().equals("")){
            record.setTargetRepository(null);
        }else {
            record.setTargetRepository(materialBo.getTargetRepositoryId());
        }


        return record;
    }

    /**
     * 初始化MaterialStuff
     * @param materialBo 包含 name count targetRepositoryId materialTypicalId
     * @return
     */
    public static MaterialStuff initMaterialStuff(MaterialBo materialBo){
        MaterialStuff materialStuff = new MaterialStuff();

        materialStuff.setName(materialBo.getName());//批次号
        materialStuff.setStorageTime(new Date());
        materialStuff.setStuffId(UUIDUtils.getId());
        materialStuff.setInRepository(Long.valueOf(materialBo.getCount()));
        materialStuff.setOutRepository(Long.valueOf(0));
        materialStuff.setRepositoryId(materialBo.getTargetRepositoryId());
        materialStuff.setStuffTypicalId(materialBo.getMaterialTypicalId());

        return materialStuff;
    }

}
